/*
 * File: exercise13.cpp
 * -------------------
 * addCommas function 
 * compile command :
 * g++ -Wall -g exercise13.cpp -o exercise13 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include <string>
#include "simpio.h"
using namespace std;

string addCommas(string digits);

int main()
{
	while(true)
	{
		string digits;
		cout<<"Enter a number: ";
		getline(cin, digits);
		if(digits == "") break;
		cout<< addCommas(digits)<<endl;
	}
	return 0;
}

string addCommas(string digits)
{
	int nchars = digits.length();
	if(nchars <= 3)
		return digits;
	for(int i = nchars - 3; i > 0; i -=3)
		digits.insert(i, ",");
	return digits;
}
